# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: shyokou <shyokou at gmail dot com>
# Contributor: N. Izumi aka izmntuk

pkgname=meek
pkgver=0.38.0
pkgrel=1
arch=('loong64' 'x86_64')
pkgdesc='A pluggable transport proxy written in Go'
optdepends=('tor')
url='https://trac.torproject.org/projects/tor/wiki/doc/meek'
license=('custom:CC0')
depends=('glibc')
makedepends=('go' 'git')
options=('!lto')
source=("git+https://git.torproject.org/pluggable-transports/meek.git#tag=v$pkgver")
sha512sums=('SKIP')

prepare() {
	cd "$srcdir"/meek
	sed 's|./meek-client|/usr/bin/meek-client|g;
	     s|./meek-server|/usr/bin/meek-server|g;
	     s|\(meek-server\.log\)|/tmp/\1|;
	     s|\(meek-client\.log\)|/tmp/\1|' -i meek-{server,client}/torrc
}

build() {
	export GOPATH="$srcdir"
	export GOBIN="$PWD"
	export CGO_CPPFLAGS="${CPPFLAGS}"
	export CGO_CFLAGS="${CFLAGS}"
	export CGO_CXXFLAGS="${CXXFLAGS}"
	export CGO_LDFLAGS="${LDFLAGS}"
	export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
	export GO111MODULE=off

	cd "$srcdir"/meek/meek-server
	go get
	make all

	cd "$srcdir"/meek/meek-client
	go get
	make all
}

package() {
	install -d "$pkgdir"/usr/{bin,share/{{doc,licenses}/$pkgname,man/man1}}
	cd "$srcdir"/meek/meek-server
	install -m755 meek-server "$pkgdir"/usr/bin
	install -Dm644 torrc "$pkgdir"/usr/share/doc/$pkgname/torrc.meek-server
	install -Dm644 README "$pkgdir"/usr/share/doc/$pkgname/README.meek-server

	cd "$srcdir"/meek/meek-client
	install -m755 meek-client "$pkgdir"/usr/bin
	install -Dm644 torrc "$pkgdir"/usr/share/doc/$pkgname/torrc.meek-client
	install -m644 ../README "$pkgdir"/usr/share/doc/$pkgname
	install -m644 ../COPYING "$pkgdir"/usr/share/licenses/$pkgname
	install -m644 ../doc/meek-{server,client}.1 "$pkgdir"/usr/share/man/man1
}
